<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../../css/common.css" media="all">

	</head>

	<style type="text/css">
		.layui-table th {
			position: relative;
			min-height: 20px;
			height: 35px;
			line-height: 20px;
			font-size: 14px;
			padding: 0px 0px;
		}

		.layui-table td {
			position: relative;
			min-height: 20px;
			height: 100%;
			line-height: 14px;
			font-size: 14px;
			padding: 0px 0px;
		}

		.layui-textarea {
			width: 302px;
			height: 40px;
		}

		.inp {
			width: 190px;
		}

		.inline-block {
			width: 310px;
			display: inline-block;
		}

		.sex {
			display: inline-block;
			width: 500px;
			position: relative;
			top: -15px;
		}
	</style>

	<body>

		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<!-- 添加活动的展示 -->
				<form class="layui-form" lay-filter="test_detail">
					<div class="layui-card">
						<!-- 活动模板 -->
						<div class="layui-card-body"
							style=" overflow-y:auto;height: 300px; border-bottom: #e0e0e0 solid 1px;">
							<div class="layui-form-item" style="display: inline-block; width: ;">
								<label class="layui-form-label">活动状态:<span style="color:red">*</span></label>
								<div class="layui-input-block on_off">

								</div>
							</div>
							<div class="layui-form-item" style="display: inline-block;">
								<label class="layui-form-label">客户端</label>
								<div class="layui-input-block icon_type">
								</div>
							</div>
							<br>
							<div class="layui-form-item" style="display: inline-block;">
								<label class="layui-form-label">活动标题：</label>
								<div class="layui-input-block">
									<input type="text" name="title" class="layui-input" id="title" autocomplete="off"
										placeholder="标题">
								</div>
							</div>
							<div class="layui-form-item" style="display: inline-block;">
								<label class="layui-form-label">活动名称：</label>
								<div class="layui-input-block">
									<input type="text" name="name" class="layui-input" id="name" autocomplete="off"
										placeholder="名称">
								</div>
							</div>
							<br>
							<div class="layui-form-item" style="display: inline-block;">
								<label class="layui-form-label" style="width:5.9375rem;">是否首页显示</label>
								<div class="layui-input-inline">
									<input type="radio" name="recommend" value="0" title="否" checked disabled>
									<input type="radio" name="recommend" value="1" title="是" disabled>
								</div>
							</div>

							<div class="layui-form-item" style="display: inline-block;">
								<label class="layui-form-label">首页倒计时</label>
								<div class="layui-input-inline">
									<input type="radio" name="istimer" value="1" title="显示" checked disabled>
									<input type="radio" name="istimer" value="0" title="不显示" disabled>
								</div>
							</div>


							<div class="layui-form-item" style="display: inline-block;">
								<label class="layui-form-label" style="width:5.9375rem;">商品排列方式</label>
								<div class="layui-input-inline">
									<input type="radio" name="sorted" value="0" title="竖排" checked disabled>
									<input type="radio" name="sorted" value="1" title="横排" disabled>
								</div>
							</div>

							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">活动类型：
									</label>
									<div class="layui-input-inline">
										<select name="type" class="seckill_type">
										</select>
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">专属等级：</label>
									<div class="layui-input-inline">
										<select name="grade" class="site_union">
										</select>
									</div>
								</div>
							</div>

							<div class="layui-form-item" style="display: inline-block;">
								<label class="layui-form-label">图标<span style="color:red">*</span></label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal"
										onclick="choose(1)">上传图标</button><span style="color:red">
										<p>建议上传340*220大小图片</p>
									</span>
									<ul class="show_img_ul" id="icon_url"></ul>
								</div>
							</div>

							<div class="layui-form-item" style="display: inline-block;">
								<label class="layui-form-label">主图<span style="color:red">*</span></label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal"
										onclick="choose(2)">上传图片</button><span style="color:red">
										<p>建议上传750*375大小图片</p>
									</span>
									<ul class="show_img_ul" id="img_url"></ul>
								</div>
							</div>
							<br>

							<div class="layui-form-item" style="display: inline-block;">
								<label class="layui-form-label">活动内容：</label>
								<div class="layui-input-block">
									<textarea class="layui-textarea" name="content" lay-verify="content"
										id=""></textarea>
								</div>
							</div>
							<div class="layui-form-item" style="display: inline-block;">
								<label class="layui-form-label">备注：</label>
								<div class="layui-input-block">
									<textarea type="text" id="notes" name="notes" autocomplete="off" placeholder="备注"
										class="layui-textarea" /></textarea>
								</div>
							</div>
							<div class="layui-form-item">
								<div style="display: inline-block;">
									<label class="layui-form-label">开始日期：</label>
									<div class="layui-input-inline">
										<input type="text" name="dates" class="layui-input" id="dates"
											autocomplete="off" placeholder="开始日期：">
									</div>
								</div>
								<div style="display: inline-block;">
									<label class="layui-form-label">开始时间：</label>
									<div class="layui-input-inline">
										<input type="text" name="times" class="layui-input" id="times"
											autocomplete="off" placeholder="开始时间：">
									</div>
								</div>
								<div style="display: inline-block;">
									<label class="layui-form-label">结束时间：</label>
									<div class="layui-input-inline">
										<input type="text" name="endtime" class="layui-input" id="endtime"
											autocomplete="off" placeholder="结束时间：">
									</div>
								</div>
								<div class="sex">
									<label class="layui-form-label" style="width: 130px;">单人购买上限：</label>
									<div class="layui-input-block">
										<input type="text" name="top_count" class="layui-input inp" id="top_count"
											autocomplete="off" placeholder="单人购买上限">
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="inline-block">
									<label class="layui-form-label">列表链接：</label>
									<div class="layui-input-block">
										<input type="text" name="url" class="layui-input inp" id="url"
											autocomplete="off" placeholder="列表链接" disabled>
									</div>
								</div>
								<div class="inline-block">
									<label class="layui-form-label">详情链接：</label>
									<div class="layui-input-block">
										<input type="text" name="url_detail" class="layui-input inp" id="url_detail"
											autocomplete="off" placeholder="详情链接" disabled>
									</div>
								</div>
								<div class="inline-block">
									<label class="layui-form-label">排序：</label>
									<div class="layui-input-block">
										<input type="text" name="oid" class="layui-input inp" id="oid"
											autocomplete="off" placeholder="排序">
									</div>
								</div>
								<div class="inline-block" style="position: relative; left: 25px; width: 400px;">
									<label class="layui-form-label">活动主题色<span style="color:red">*</span></label>
									<div class="layui-input-inline">
										<input type="text" value="" placeholder="活动主题色" class="layui-input inp"
											id="color" name='color'>
									</div>
									<div class="layui-inline" style="left: -11px;">
										<div id="test-form"></div>
									</div>
								</div>
							</div>

						</div>


						<!-- 商品列表 -->
						<div class="layui-card">
							<div class="layui-form-item">
								<label class="layui-form-label">
									<!-- 活动时间 -->
									<!-- <span style="color:red">*</span> -->
								</label>
								<div class="layui-input-inline"
									style="display: flex;align-items: center;height: 2.375rem;padding: 0.5625rem 0;">
									<!-- <input type="text" name="dates" lay-verify="required" disabled placeholder="请选择" autocomplete="on" class="layui-input limited_name"> -->
									<span id="name"></span>
									<input type="hidden" name="seckill_id" lay-verify="required" placeholder=""
										autocomplete="off" class="layui-input seckill_id">
								</div>
								<div class="layui-form-mid layui-word-aux">
									<select id="select" lay-filter="level">
										<option id="selectOp" value="">请选择一个佣金模板</option>
										<!-- <option value="1">模板1</option> -->
									</select>
									<!-- <button type="button" class="layui-btn layui-btn-sm" onclick="opentemp()">选择模板</button> -->
									<!-- <a href="Javascript:;" onclick="searchdata('market_id')">选择</a> -->
								</div>
							</div>
							<div class="layui-card-body">
								<table class="layui-table" id="testtable">
									<!-- <table class="layui-table" lay-size="sm"> -->
									<colgroup>
										<col>
										<col>
										<col>
										<col>
										<col>
									</colgroup>

									<thead>
										<tr>

											<th style="width: 100px;">商品编号</th>
											<th style="width: 250px;">商品名</th>
											<!-- <th style="width: 70px;">成本价</th> -->
											<th style="width: 70px;">会员价</th>
											<!-- <th>原抵扣积分zhu</th> -->
											<th style="width: 70px;">团购价</th>
											<!-- <th>积分比例%zhu</th> -->
											<!-- <th>积分使用zhu</th> -->
											<th style="width: 70px;">补贴</th>
											<th style="width: 70px;">团人数</th>
											<th style="width: 70px;">中奖人数</th>
											<th style="width: 120px;">显示已参团人数</th>

											<th style="width: 70px;">活动数量</th>
											<th style="width: 120px;">显示已购数量</th>
											<th style="width: 70px;">购买上限</th>
											<th style="width: 70px;">显示数量</th>

											<th style="width: 60px;">团时长</th>
											<th style="width: 90px;">发起佣金</th>
											<th style="width: 90px;">直推佣金</th>
											<th style="width: 90px;">间推佣金</th>
											<th style="width: 90px;">团长佣金</th>
											<th style="width: 90px;">管理奖</th>
											<th style="width: 100px;">合伙人佣金</th>
											<th style="width: 100px;">服务站佣金</th>
											<th style="width: 40px;">排序</th>
										</tr>
									</thead>

									<tbody id="temp">
										<tr>
											<td style="width: 100px;">
												<div class="flex">
													<!-- <input class="layui-input layui-input-choose" onfocus="choosedata()" name="" value="zhu" /> -->
													<button type="button" class="layui-btn layui-btn-sm"
														onclick="choosedata()"><i
															class="layui-icon layui-icon-search"></i></button>
												</div>
											</td>
											<td style="width: 250px;"></td>
											<td style="width: 70px;"></td>
											<td style="width: 70px;"></td>
											<td style="width: 70px;"></td>
											<td style="width: 70px;"></td>
											<td style="width: 70px;"></td>
											<td style="width: 120px;"></td>
											<td style="width: 70px;"></td>
											<td style="width: 120px;"></td>

											<td style="width: 70px;"></td>
											<td style="width: 70px;"></td>
											<td style="width: 60px;"></td>
											<td style="width: 90px;"></td>
											<td style="width: 90px;"></td>
											<td style="width: 90px;"></td>
											<td style="width: 90px;"></td>
											<td style="width: 90px;"></td>
											<td style="width: 100px;"></td>
											<td style="width: 100px;"></td>
											<td style="width: 40px;"></td>
										</tr>
									</tbody>
								</table>
							</div>
						</div>

					</div>
					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<button type="reset" class="layui-btn layui-btn-primary">重置</button>
								<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
				</form>

				<!-- 添加商品的展示 -->

			</div>
		</div>
		<script src="../../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../../js/jquery.min.js"></script>
		<script src="../../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../../js/common.js"></script>
		<script>
			// 添加活动 
			var _data = {
				id: getParam('id')
			}
			var _member = {

			}
			layui.config({
				base: '../../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laytpl', 'laydate', 'layedit', 'upload', 'colorpicker', 'table'], function() {
				var $ = layui.$,
					admin = layui.admin,
					upload = layui.upload,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					layedit = layui.layedit,
					colorpicker = layui.colorpicker,
					form = layui.form;
				table = layui.table;

				var img_arr1 = [],
					img_arr2 = [];

				on_off_show('radio')
				seckill_type_show_shop("option")
				site_union_show("option")
				icon_type_show_shop('checkbox')
				//日期时间选择器
				laydate.render({
					elem: '#dates',
					type: 'date'
				});
				//日期时间选择器
				laydate.render({
					elem: '#times',
					type: 'time'
				});
				//日期时间选择器
				laydate.render({
					elem: '#endtime',
					type: 'datetime'
				});
				//表单赋值
				colorpicker.render({
					elem: '#test-form',
					done: function(color) {
						$('#color').val(color);
					}
				});
				if (_data.id) {
					setTimeout(function() {
						initdata();
					}, 300)
				}
				//监听提交 活动的
				// form.on('submit(demo1)', function(data) {
				// 	var data = data.field;
				// 	_data = Object.assign(_data, data);
				// 	_data.icon_url = img_arr1.join(',');
				// 	_data.img_url = img_arr2.join(',');

				// 	_data.client = ''
				// 	for (item in data){ 
				// 		if(/^c/.test(item)){
				// 			if(item.substr(0,6) == 'client'){
				// 				_data.client += data[item]+','
				// 				console.log(item)
				// 				console.log(data[item])
				// 			} 
				// 		} 
				// 	} 
				// 	_data.client = (_data.client.substring(_data.client.length-1) == ',') ? _data.client.substring(0,_data.client.length-1) : _data.client;

				// 	layer.confirm('确定要提交数据？', function() {
				// 		loading();
				// 		if(_data.id) {
				// 			submitdata(server.shop_promotion_temp_edit);
				// 		} else {
				// 			delete _data.id
				// 			submitdata(server.shop_promotion_temp_insert);
				// 		}
				// 	}, function() {
				// 		layer.msg('取消操作');
				// 	});
				// 	return false;
				// });

				function submitdata(_url) {
					console.log(_url);
					$.post(_url, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.msg(res.msg);
							}
							closeloading();
						} else {
							closeloading();
							layer.msg('服务器连接错误');
						}
					});
				}

				function initdata() {
					$.get(shop.promotion.temp.detail, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								var data = res.seckill

								data.data.icon_url ? createli(data.data.icon_url, 'icon_url', '1') : '';
								data.data.img_url ? createli(data.data.img_url, 'img_url', '2') : '';


								// form 返回的数据
								var a = form.val("test_detail", data.data);
								console.log(a);
								form.render();
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}

				window.searchdata = function(type) {
					switch (type) {
						case 'shopid':
							layer.open({
								type: 2,
								title: '选择',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['90%', '90%'],
								content: 'choose_shop.html',
								end: function() {},
								success: function() {}
							});
							break;
					}
				}

				window.choose = function(data) {
					layer.open({
						type: 2,
						title: '上传图片',
						shadeClose: false,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['700px', '400px'],
						content: 'up_report.html?type=' + data,
						end: function() {},
						success: function() {}
					});
				}

				window.getimg = function(data, type) {
					console.log(data);
					if (data) {
						switch (type) {
							case '1':
								createli(data, 'icon_url', type)
								break;
							case '2':
								createli(data, 'img_url', type)
								break;
							default:
								break;
						}
					}
				}

				window.delimg = function(i, type, _self) {
					var _type = String(type)
					layer.confirm('确定要删除图片？', function(index) {
						switch (_type) {
							case '1':
								img_arr1.splice(i, 1)
								break;
							case '2':
								img_arr2.splice(i, 1)
								break;
							default:
								break;
						}
						$(_self).parent().remove();
						layer.close(index)
					}, function() {
						layer.msg('取消操作');
					});

				}





				function createli(data, dom, type) {
					// console.log(data);
					var lihtml = '';
					switch (type) {
						case '1':
							if (data.indexOf(',') == -1) {
								img_arr1.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr1.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr1.length; i++) {
								lihtml += '<li class="show_img_li">' +
									'<img src=' + img_arr1[i] + ' >' +
									'<p onclick="delimg(' + i + ',1,this)">删除</p>' +
									'</li>'
							}
							break;
						case '2':
							if (data.indexOf(',') == -1) {
								img_arr2.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr2.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr2.length; i++) {
								lihtml += '<li class="show_img_li">' +
									'<img src=' + img_arr2[i] + ' >' +
									'<p onclick="delimg(' + i + ',2,this)">删除</p>' +
									'</li>'
							}
							break;
						default:
							break;
					}
					$('#' + dom).html(lihtml);
				}



				//监听提交 -----------------------------

				// 监听选择模板
				form.on('select(level)', function(data) {
					if (data.value !== "") {
						console.log(data.value)
						window.tempList.forEach(item => {
							if (data.value === item.id) {
								tempObj = item
							}
						})
					} else if (data.value === "") {

					}
				})


				$("button[type=reset]").on("click", function() {
					_data = {}
					tempObj = {}
					document.getElementById("form").reset();
				});


				//监听提交
				form.on('submit(demo1)', function(data) {
					console.log(data);
					var data = data.field;
					_data = Object.assign(_data, data);
					var goods_data = [];
					var testtable = document.getElementById('testtable');
					console.log(testtable, 'testtable')
					// console.log(testtable.rows.length);
					var rows = testtable.rows;
					console.log(rows.length, '90000')
					for (var i = 0; i < rows.length; i++) {
						var cells = rows[i].cells;
						var skuid = $(cells).find('input[name=skuid]').val(),
							price = $(cells).find('input[name=price]').val(), //团购价格
							stock = $(cells).find('input[name=stock]').val(), //库存数量
							sales = $(cells).find('input[name=sales]').val(), //已购买数量
							num = $(cells).find('input[name=num]').val(), //显示数量


							//score = $(cells).find('input[name=score]').val(),
							//score_scale = $(cells).find('input[name=score_scale]').val(), 

							top_count = $(cells).find('input[name=top_count]').val(), //购买上限

							subsidy = $(cells).find('input[name=subsidy]').val(), //补贴

							group_num = $(cells).find('input[name=group_num]').val(), //团人数
							group_wnum = $(cells).find('input[name=group_wnum]').val(), //中奖人数
							group_onum = $(cells).find('input[name=group_onum]').val(), //显示团参与人数

							duration = $(cells).find('input[name=duration]').val(),
							launch_fee = $(cells).find('input[name=launch_fee]').val(),
							leader_fee = $(cells).find('input[name=leader_fee]').val(), // 团长佣金
							direct_fee = $(cells).find('input[name=direct_fee]').val(), // 直推佣金
							indirect_fee = $(cells).find('input[name=indirect_fee]').val(),
							/* 间推佣金 */
							team_fee = $(cells).find('input[name=team_fee]').val(), // 团队佣金=== 管理奖
							copartner_fee = $(cells).find('input[name=copartner_fee]').val(), // 合伙人佣金
							station_fee = $(cells).find('input[name=station_fee]').val(), // 服务站佣金

							oid = $(cells).find('input[name=oid]').val();
						console.log(skuid, 'id')
						if (skuid) {
							goods_data.push({
								'skuid': skuid,
								'price': price,

								'subsidy': subsidy,
								'group_num': group_num,
								'group_wnum': group_wnum,
								'group_onum': group_onum,

								'stock': stock,
								'num': num,
								//'score' : score,
								//'score_scale' : score_scale, 
								'top_count': top_count,
								'sales': sales,
								'duration': duration,
								'launch_fee': launch_fee,
								'leader_fee': leader_fee,
								'direct_fee': direct_fee,
								'indirect_fee': indirect_fee,
								'team_fee': team_fee,
								'copartner_fee': copartner_fee,
								'station_fee': station_fee,
								'oid': oid
							})
						}
					}

					_data.goods_data = JSON.stringify(goods_data)
					console.log(goods_data, '000000')
					console.log(JSON.stringify(_data));

					// layer.confirm('确定要提交数据？', function() {
					// 	loading();
					// 	if (_data.id) {
					// 		//submitdata(server.limited_goods_add);
					// 	} else {
					// 		delete _data.id
					// 		submitdata(server.seckill_goods_add);
					// 	}
					// }, function() {
					// 	layer.msg('取消操作');
					// });
					// return false;
				});


				function submitdata(_url) {
					$.post(_url, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.closeAll('loading')
								layer.msg(res.msg);
							}
							closeloading();
						} else {
							closeloading();
							layer.msg('服务器连接错误');
						}
					});
				}
				window.tempList = []
				// 获取模板数据
				// window.getTempLate()
				getTempLate = function() {
					$.post(server.shop_feetemp_list, {}, function(res, status) {
						if (res.code === 0) {
							let data = res.seckill_fee_temp.data;
							window.tempList = data
							let html = '';
							for (var i = 0; i < data.length; i++) {
								html += `<option value="${data[i].id}">${data[i].name}</option>`
							}
							$("#selectOp").after(html)
							form.render();
						}
					})
				}
				getTempLate()


				window.getdata = function(data, name, id) {
					var html;
					var a = 1;
					for (var i = 0; i < data.length; i++) {
						html += '<tr>' +
							`<td id="code${data[i].skuid}">` + (a + i) + '</td>' +
							'<td><div class="flex"><input  class="layui-input"  name="skuid" value=' + data[i]
							.skuid + ' /></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="skuname" value=' + (data[i]
								.skuname ? data[i].skuname : "") + '></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="price_member" value=' + data[i]
							.price_member + ' /></div></td>' +
							//'<td><div class="flex"><input  class="layui-input"  name="score_old" lay-verify="required" value="' + (data[i].score?data[i].score:'0')+ '"/></div></td>' +

							// `<td><div class="flex"><input onkeyup="inputChange(this, data[i])"  class="layui-input" name="price" lay-verify="required" value="' + (data[i].limit_price?data[i].limit_price:'')+ '"/></div></td>` +
							`<td><div class="flex"><input class="layui-input" name="price" lay-verify="required" value="${data[i].limit_price?data[i].limit_price:''}" /></div></td>` +
							//							'<td><div class="flex"><input  class="layui-input"  name="score_scale" lay-verify="required" /></div></td>' +
							//'<td><div class="flex"><input  class="layui-input"  name="score" lay-verify="required" /></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="subsidy" lay-verify="required" /></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="group_num" lay-verify="required" /></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="group_wnum" lay-verify="required" /></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="group_onum" lay-verify="required" /></div></td>' +

							'<td><div class="flex"><input  class="layui-input"  name="stock" lay-verify="required" /></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="sales"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="top_count"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="num"/></div></td>' +

							'<td><div class="flex"><input  class="layui-input"  name="duration"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="launch_fee"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="direct_fee"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="indirect_fee"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="leader_fee"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="team_fee"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="copartner_fee"/></div></td>' +
							'<td><div class="flex"><input  class="layui-input"  name="station_fee"/></div></td>' +

							'<td><div class="flex"><input  class="layui-input"  name="oid" value=' + (a + i) +
							' /></div></td>' +
							'</tr>';
					}

					$('#temp').before(html)
				}

				window.choosedata = function() {
					layer.open({
						type: 2,
						title: '选择',
						shadeClose: false,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['80%', '80%'],
						content: 'list.html',
						end: function() {},
						success: function() {}
					});
				}

				window.opentemp = function() {
					// alert('打开模板')
					temp.style.display = 'block'
					// 获取模板
					// layer.open({
					// 	type: 2,
					// 	title: '选择',
					// 	shadeClose: false,
					// 	shade: 0.5,
					// 	maxmin: true,
					// 	area: ['800px', '98%'],
					// 	content: '../../seckill_feetemp/list.html',
					// 	end: function() {},
					// 	success: function() {}
					// })
				}

				window.searchdata = function(type) {
					switch (type) {
						case 'skuid':
							layer.open({
								type: 2,
								title: '选择',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['800px', '98%'],
								content: 'choose_skuid.html',
								end: function() {},
								success: function() {}
							});
							break;
						case 'market_id':
							layer.open({
								type: 2,
								title: '选择',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['800px', '90%'],
								content: 'choose_limited.html',
								end: function() {},
								success: function() {}
							});
							break;
					}
				}
			});

			$(document).on('blur', "input[name=price]", function(e) {
				var tr = e.currentTarget.parentElement.parentElement.parentElement
				// layer.confirm('是否使用模板?',function(){
				// 	layer.closeAll('dialog');
				// 	if (tempObj.name) {
				// 		layer.msg(`当前使用模板:${tempObj.name}`)
				// 		let price = $(tr).find("input[name=price]").val()
				// 		price = parseInt(price)
				// 		console.log(price, '输入的价格')
				// 		let launch_fee = getBili(tempObj.launch_fee, price) // 发起者奖励%
				// 		let leader_fee = getBili(tempObj.leader_fee, price) // 团长奖励%
				// 		let team_fee = getBili(tempObj.team_fee, price) // 团队奖励%
				// 		let indirect_fee = getBili(tempObj.indirect_fee, price) // 间推奖励%
				// 		let direct_fee = getBili(tempObj.direct_fee, price) // 直推奖励%
				// 		let copartner_fee = getBili(tempObj.copartner_fee, price) // 合伙人奖励%
				// 		console.log(launch_fee, '发起者奖励')
				// 		$(tr).find("input[name=launch_fee]").val(launch_fee)
				// 		$(tr).find("input[name=leader_fee]").val(leader_fee)
				// 		$(tr).find("input[name=team_fee]").val(team_fee)
				// 		$(tr).find("input[name=indirect_fee]").val(indirect_fee)
				// 		$(tr).find("input[name=direct_fee]").val(direct_fee)
				// 		$(tr).find("input[name=copartner_fee]").val(copartner_fee)
				// 	} else {
				// 		$(tr).find("input[name=price]").val('')
				// 		layer.msg('请先选择模板');
				// 	}
				// },function(){
				// 	layer.msg('取消操作');
				// })
				if (tempObj.name) {
					if (!$(tr).find("input[name=price]").val()) {
						$(tr).find("input[name=launch_fee]").val('')
						$(tr).find("input[name=leader_fee]").val('')
						$(tr).find("input[name=team_fee]").val('')
						$(tr).find("input[name=indirect_fee]").val('')
						$(tr).find("input[name=direct_fee]").val('')
						$(tr).find("input[name=copartner_fee]").val('')
						$(tr).find("input[name=station_fee]").val('')
					} else {
						let price = $(tr).find("input[name=price]").val()
						price = parseInt(price)
						console.log(price, '输入的价格')
						let launch_fee = getBili(tempObj.launch_fee, price) // 发起者奖励%
						let leader_fee = getBili(tempObj.leader_fee, price) // 团长奖励%
						let team_fee = getBili(tempObj.team_fee, price) // 团队奖励%
						let indirect_fee = getBili(tempObj.indirect_fee, price) // 间推奖励%
						let direct_fee = getBili(tempObj.direct_fee, price) // 直推奖励%
						let copartner_fee = getBili(tempObj.copartner_fee, price) // 合伙人奖励%
						let station_fee = getBili(tempObj.station_fee, price) // 服务站奖励%
						console.log(launch_fee, '发起者奖励')
						$(tr).find("input[name=launch_fee]").val(launch_fee)
						$(tr).find("input[name=leader_fee]").val(leader_fee)
						$(tr).find("input[name=team_fee]").val(team_fee)
						$(tr).find("input[name=indirect_fee]").val(indirect_fee)
						$(tr).find("input[name=direct_fee]").val(direct_fee)
						$(tr).find("input[name=copartner_fee]").val(copartner_fee)
						$(tr).find("input[name=station_fee]").val(station_fee)
					}
				} else {

				}
			})



			$(document).on('keyup', "input[name=group_num]", function(e) {
				var tr = e.currentTarget.parentElement.parentElement.parentElement
				if (!$(tr).find("input[name=price]").val()) {
					layer.msg('请先输入团购价')
					$(tr).find("input[name=group_num]").val('')
				} else if (tempObj.id !== undefined) {
					if (!$(tr).find("input[name=group_num]").val()) {
						// 重新计算比例
						console.log('重新计算比例')
						let price = $(tr).find("input[name=price]").val()
						price = parseInt(price)
						console.log(price, '输入的价格')
						let launch_fee = getBili(tempObj.launch_fee, price) // 发起者奖励%
						let leader_fee = getBili(tempObj.leader_fee, price) // 团长奖励%
						let team_fee = getBili(tempObj.team_fee, price) // 团队奖励%
						let indirect_fee = getBili(tempObj.indirect_fee, price) // 间推奖励%
						let direct_fee = getBili(tempObj.direct_fee, price) // 直推奖励%
						let copartner_fee = getBili(tempObj.copartner_fee, price) // 合伙人奖励%
						let station_fee = getBili(tempObj.station_fee, price) // 服务站奖励%
						console.log(launch_fee, '发起者奖励')
						$(tr).find("input[name=launch_fee]").val(launch_fee)
						$(tr).find("input[name=leader_fee]").val(leader_fee)
						$(tr).find("input[name=team_fee]").val(team_fee)
						$(tr).find("input[name=indirect_fee]").val(indirect_fee)
						$(tr).find("input[name=direct_fee]").val(direct_fee)
						$(tr).find("input[name=copartner_fee]").val(copartner_fee)
						$(tr).find("input[name=station_fee]").val(station_fee)
					} else {
						// 填写完团人数重新计算
						let price = $(tr).find("input[name=price]").val()
						price = parseInt(price)
						let launch_fee = $(tr).find("input[name=launch_fee]").val()
						let leader_fee = $(tr).find("input[name=leader_fee]").val()
						let team_fee = $(tr).find("input[name=team_fee]").val()
						let indirect_fee = $(tr).find("input[name=indirect_fee]").val()
						let direct_fee = $(tr).find("input[name=direct_fee]").val()
						let copartner_fee = $(tr).find("input[name=copartner_fee]").val()
						let station_fee = $(tr).find("input[name=station_fee]").val()
						let group_num = $(tr).find("input[name=group_num]").val()
						$(tr).find("input[name=launch_fee]").val(getT(getBili(tempObj.launch_fee, price), group_num))
						$(tr).find("input[name=leader_fee]").val(getT(getBili(tempObj.leader_fee, price), group_num))
						$(tr).find("input[name=team_fee]").val(getT(getBili(tempObj.team_fee, price), group_num))
						$(tr).find("input[name=indirect_fee]").val(getT(getBili(tempObj.indirect_fee, price), group_num))
						$(tr).find("input[name=direct_fee]").val(getT(getBili(tempObj.direct_fee, price), group_num))
						$(tr).find("input[name=copartner_fee]").val(getT(getBili(tempObj.copartner_fee, price),
							group_num))
						$(tr).find("input[name=station_fee]").val(getT(getBili(tempObj.station_fee, price), group_num))
					}
				}
			})

			function getBili(num1, num2) {
				// let num = 0
				// if (num2 == 100) {
				// 	num = (Math.round(num1/num2 * 10000) / 100.00);
				// } else {
				// 	num = (Math.round(num1/num2 * 100) / 100.00);
				// }
				let num = Math.round(num1 * num2) / 100
				return num.toFixed(2)
			}

			function getT(num1, num2) {
				let num = num1 / num2
				return num.toFixed(2)
			}
		</script>
	</body>

</html>
